//
//  CommonDiseaseViewController.m
//  必争医疗
//
//  Created by 付正 on 14-11-19.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "CommonDiseaseViewController.h"
#import "CommonDiseaseCollectionViewCell.h"
#import "CommonDiseaseCollectionReusableView.h"
@interface CommonDiseaseViewController ()<UISearchBarDelegate, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>

@end

@implementation CommonDiseaseViewController
- (void)dealloc
{
    [_bigScroll release];
    [_mysearch release];
    [_seg release];
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.leftCollectArray = [NSMutableArray array];
        NSMutableArray *work = [NSMutableArray arrayWithObjects:@"狐臭",@"脱发", @"口臭", @"痔疮",@"便秘",@"风寒感冒",@"失眠",@"风热感冒",@"更多", nil];
        NSMutableDictionary *workdic = [NSMutableDictionary dictionary];
        [workdic setValue:@"上班族" forKey:@"type"];
        [workdic setValue:work forKey:@"array"];
        [_leftCollectArray addObject:workdic];
        
        NSMutableArray *man = [NSMutableArray arrayWithObjects:@"早泄",@"阳痿",@"前列腺炎",@"前列腺增生",@"包皮过长",@"包皮龟头炎",@"尿道炎",@"包茎",@"更多", nil];
        NSMutableDictionary *mandic = [NSMutableDictionary dictionary];
        [mandic setValue:@"男性" forKey:@"type"];
        [mandic setValue:man forKey:@"array"];
        [_leftCollectArray addObject:mandic];
        
        NSMutableArray *woman = [NSMutableArray arrayWithObjects:@"月经失调", @"多囊卵巢综合征",@"阴道炎",@"宫颈糜烂",@"痛经",@"闭经",@"慢性盆腔炎",@"慢性附件炎",@"更多",nil];
        NSMutableDictionary *womandic = [NSMutableDictionary dictionary];
        [womandic setValue:@"女性" forKey:@"type"];
        [womandic setValue:woman forKey:@"array"];
        [_leftCollectArray addObject:womandic];

        NSMutableArray *oldman = [NSMutableArray arrayWithObjects:@"通风",@"高血压",@"2型糖尿病",@"1型糖尿病",@"心脏病",@"支气管炎",@"心律失常",@"耳聋",@"更多",nil];
        NSMutableDictionary *oldmandic = [NSMutableDictionary dictionary];
        [oldmandic setValue:@"老人" forKey:@"type"];
        [oldmandic setValue:oldman forKey:@"array"];
        [_leftCollectArray addObject:oldmandic];
        
         NSMutableArray *child = [NSMutableArray arrayWithObjects:@"新生儿黄疸",@"手足口病",@"小儿感冒",@"小儿呕吐",@"小儿腹泻",@"小儿发热",@"小儿肺炎",@"鹅口疮",@"更多",nil];
        NSMutableDictionary *childdic = [NSMutableDictionary dictionary];
        [childdic setValue:@"小孩" forKey:@"type"];
        [childdic setValue:child forKey:@"array"];
        [_leftCollectArray addObject:childdic];
        
        
        
        
        self.rightCollectArray = [NSMutableArray array];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view setBackgroundColor:[UIColor whiteColor]];
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.title = @"常见病";
    [self.tabBarController.tabBar setHidden:YES];
    //执行方法
    [self creatSearchBar];
    [self creatSegmented];
    [self creatScroll];
}



#pragma mark -
#pragma mark 创建搜索
- (void)creatSearchBar
{
    self.mysearch = [[UISearchBar alloc] initWithFrame:CGRectMake(20, 20, self.view.frame.size.width - 40, self.view.frame.size.height / 18)];
    [_mysearch setPlaceholder:@"查询药品、疾病、症状、医生等"];
    [_mysearch setBarStyle:UIBarStyleDefault];
    [_mysearch setTintColor:[UIColor clearColor]];
    [_mysearch resignFirstResponder];
    _mysearch.delegate = self;
    [self.view addSubview:_mysearch];
}


#pragma mark -
#pragma mark SegmentedControl
- (void)creatSegmented
{
    NSArray *arr = [NSArray arrayWithObjects:@"按人群", @"按科室", nil];
    self.seg = [[UISegmentedControl alloc] initWithItems:arr];
    [_seg setBackgroundColor:[UIColor whiteColor]];
    [_seg setFrame:CGRectMake(10, _mysearch.frame.origin.y + _mysearch.frame.size.height + 20, self.view.frame.size.width - 20, self.view.frame.size.height / 18)];
    [self.view addSubview:_seg];
    [_seg release];
}


#pragma mark -
#pragma mark 创建scrollView
- (void)creatScroll
{
    self.bigScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, _seg.frame.origin.y + _seg.frame.size.height, self.view.frame.size.width, self.view.frame.size.height - _seg.frame.origin.y + _seg.frame.size.height)];
    [_bigScroll setContentSize:CGSizeMake(self.view.frame.size.width * 2,self.view.frame.size.height - _seg.frame.origin.y + _seg.frame.size.height)];
    [self.view addSubview:_bigScroll];
    [_bigScroll setBackgroundColor:[UIColor yellowColor]];
    [_bigScroll release];
    
    
    UIView *leftview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - _seg.frame.origin.y + _seg.frame.size.height)];
    [leftview setBackgroundColor:[UIColor cyanColor]];
  
    
    
    UIView *rightview = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height - _seg.frame.origin.y - _seg.frame.size.height)];
    [rightview setBackgroundColor:[UIColor blueColor]];
   
    
    
    [_bigScroll addSubview:leftview];
    [_bigScroll addSubview:rightview];
    [leftview release];
    [rightview release];
    
//   创建collectionView
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    
    [layout setItemSize:CGSizeMake(80, 40)];
    
    [layout setMinimumInteritemSpacing:0];
    [layout setMinimumLineSpacing:0];
    
    layout.sectionInset = UIEdgeInsetsMake(0, 30, 0, 30);
    
    UICollectionView *leftCollect = [[UICollectionView alloc] initWithFrame:CGRectMake(0,0, self.view.frame.size.width, self.view.frame.size.height - self.view.frame.size.height / 18 - self.view.frame.size.height / 18 - 100) collectionViewLayout:layout];
    leftCollect.dataSource = self;
    leftCollect.delegate = self;
    [leftCollect setBackgroundColor:[UIColor whiteColor]];

    
    [leftCollect registerClass:[CommonDiseaseCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head"];
    
    [leftCollect registerClass:[CommonDiseaseCollectionViewCell class] forCellWithReuseIdentifier:@"cellIdentify"];


    
    [leftview addSubview:leftCollect];
    [leftCollect release];
    [layout release];

}


- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return [_leftCollectArray count];
}



- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    NSArray *arr = [[_leftCollectArray objectAtIndex:section] objectForKey:@"array"];
    return [arr count];
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
{
    return CGSizeMake(80, 40);
}


- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    CommonDiseaseCollectionReusableView *head = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head" forIndexPath:indexPath];
    
    NSMutableDictionary *dic = [_leftCollectArray objectAtIndex:indexPath.section];
    
    head.aLabel.text = [dic objectForKey:@"type"];
    head.aLabel.textAlignment = NSTextAlignmentCenter;
    return head;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CommonDiseaseCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentify" forIndexPath:indexPath];
    NSMutableDictionary *dic = [_leftCollectArray objectAtIndex:indexPath.section];
    NSMutableArray *arr = [dic objectForKey:@"array"];

    cell.aLabel.text = [arr objectAtIndex:indexPath.item];
    return cell;
}














- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
